package com.hurl.waguji.base;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Configuration {

	public static final String CONFIG_FILE = "waguji.properties";
	private static final String KEY_ADMIN_PASSWORD = "admin.password";
	private static final String KEY_TENCENT_CJMX_FILE_LOCATION = "tencent.cjmx.file.location";
	/**
	 * 当前的系统模式
	 */
	public static final String CONFIG_DEBUG_MODE = "debugMode";
	
	private static Properties configs = buildConfiguration();
	
	//business logic
	
	public static boolean isDebugMode(){
		return getBoolean("debugMode");
	}
	
	private static String getString(String key){
		return configs.getProperty(key);
	}
	
	private static int getInt(String key){
		return Integer.parseInt(configs.getProperty(key));
	}
	
	private static boolean getBoolean(String key){
		return Boolean.parseBoolean(configs.getProperty(key));
	}
	public static String getAdminPassword(){
		return configs.getProperty(KEY_ADMIN_PASSWORD);
	}
	public static String getTencentCjmxFileLocation(){
		return configs.getProperty(KEY_TENCENT_CJMX_FILE_LOCATION);
	}
	/**
	 * 从配置文件加载系统配置
	 * @return
	 */
	private static Properties buildConfiguration(){
		ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
		InputStream is = classLoader.getResourceAsStream(CONFIG_FILE);
		Properties props = new Properties();
		try {
			props.load(is);
		} catch (IOException e) {
			e.printStackTrace();
			throw new WagujiRuntimeException(e.getMessage(),e);
		}
		return props;
	}
	
	
}
